#ifndef LOGGER_H
#define LOGGER_H

#include <iostream>
#include "pthread.h"
class LogError;
class Logger
{

	private:
	std::ostream&	out;
	bool			m_Enable;
	bool			m_bLogToScreen;
	pthread_mutex_t	m_lock;

	public:
		Logger(std::ostream& _out, bool Enable, bool logtoscrren ):out(_out),m_Enable( Enable  ), m_bLogToScreen( logtoscrren )
		{
			pthread_mutex_init( &m_lock, NULL );

		}
		~Logger()
		{
			pthread_mutex_destroy( &m_lock );
		}
		template<typename T>
		Logger& operator<<(const T& v)
		{
			pthread_mutex_lock( &m_lock );
			if( m_Enable )
			{
				out << v;
//				out.flush();
				if( m_bLogToScreen )
				{
					std::cout<<v;
				}
			}
			pthread_mutex_unlock( &m_lock );
			return *this;
		}
};

#endif
